package com.askinhand.service.impl;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.askinhand.bean.AudioQues;
import com.askinhand.bean.PictureQues;
import com.askinhand.dao.impl.PictureQuesDAO;
import com.askinhand.service.IPictureQuestionService;

public class PictureQuestionService implements IPictureQuestionService{

	PictureQuesDAO pictureQuesDAO;

	public PictureQuesDAO getPictureQuesDAO() {
		return pictureQuesDAO;
	}

	public void setPictureQuesDAO(PictureQuesDAO pictureQuesDAO) {
		this.pictureQuesDAO = pictureQuesDAO;
	}
	//ȡ�ø������ʵ���ʷ
	//����ֵ��һ��arraylist�����ٷֱ���������arraylist��һ����audio����һ����pic
	public ArrayList personalQuesReturn(String uid) {
		// TODO Auto-generated method stub
		ArrayList<PictureQues> pic=new ArrayList<PictureQues>();
		
		
		List li=pictureQuesDAO.findByUid(Integer.parseInt(uid));
		Iterator it=li.iterator();
		while(it.hasNext()){
			PictureQues picques=(PictureQues)it.next();
			pic.add(picques);
			
		}

		
		return pic;
	}

	public ArrayList questionFind(String type, String status) {
		// TODO Auto-generated method stub
		
		ArrayList<PictureQues> result=new ArrayList<PictureQues>();
		List list=pictureQuesDAO.findAll();
		if(list.size()>0){
			Iterator it=list.iterator();
			while(it.hasNext()){
				PictureQues current=(PictureQues) it.next();
				System.out.println(current.getType()+" "+type+" "+current.getStatus()+" "+status);
				System.out.println(current.getType().equals(type));
				System.out.println(current.getStatus().equals(status));
				if((current.getType().equals(type))&&(current.getStatus().equals(status)))
					result.add(current);
				
			}
			
		}
		
		return result;
	}

	public String save(PictureQues pq) {
		// TODO Auto-generated method stub
		try{pictureQuesDAO.save(pq);
		  return "success";
		}catch(Exception e){
		return "fail";
		}
		
	}
	
	
}
